package com.zkx.mvp.view.wight;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.widget.ImageView;

import com.zkx.mvp.R;

/**
 * Author：zhangkx on 2017/6/28 16:48
 * Email：zkx9025@163.com
 * 加载对话框
 */

public class LoadingDialog extends AlertDialog {
    private ImageView imageview;
    private AnimationDrawable mAnimation;

    public LoadingDialog(Context context, int theme) {
        super(context, theme);
    }

    public LoadingDialog(Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pop_loading_layout);
        imageview = (ImageView) findViewById(R.id.imageview);
        imageview.setBackgroundResource(R.drawable.loading);
        mAnimation = (AnimationDrawable) imageview.getBackground();
        // 为了防止在onCreate方法中只显示第一帧的解决方案之一
        imageview.post(new Runnable() {
            @Override
            public void run() {
                mAnimation.start();
            }
        });
        setCancelable(true);
    }
}
